package com.yloveg.impl;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.yloveg.dao.SRoleMapper;
import com.yloveg.dao.VActivityMapper;
import com.yloveg.dao.VGiftMapper;
import com.yloveg.entity.SRole;
import com.yloveg.entity.VActivity;
import com.yloveg.entity.VGift;
import com.yloveg.service.SRoleService;
import com.yloveg.service.VActivityService;
import com.yloveg.service.VGiftService;

@Service
public class VActivityServiceImpl implements VActivityService {

	@Autowired
    private VActivityMapper vActivityMapper;

	@Override
	public PageInfo<VActivity> queryActivityPage(int page, int limit, String status) {
		PageHelper.startPage(page, limit);
		List<VActivity> vActivityList=null;
		if(StringUtil.isNotEmpty(status)) {
			//未开始
			if("1".equals(status)) {
				vActivityList = vActivityMapper.queryVActivityNotOpen();
			}
			//活动中
            if("2".equals(status)) {
            	vActivityList = vActivityMapper.queryVActivityOpen();
			}
            //已结束
            if("3".equals(status)) {
            	vActivityList = vActivityMapper.queryVActivityOver();
            }
		}else {
			//查询全部
			vActivityList = vActivityMapper.queryVActivity();
		}
		PageInfo<VActivity> resultPage=new PageInfo<VActivity>(vActivityList);
		return resultPage;
	}

	@Override
	public int insertActivity(VActivity vactivity) {
		vactivity.setCreateTime(new Date());
		vactivity.setSts("Y");
		vactivity.setFlag("Y");
		return vActivityMapper.insert(vactivity);
	}

	@Override
	public int updateByPrimaryKeySelective(VActivity vactivity) {
		vactivity.setUpdateTime(new Date());
		return vActivityMapper.updateByPrimaryKeySelective(vactivity);
	}

	@Override
	@Cacheable(value="selectByPrimaryKey",key="#id")
	public VActivity selectByPrimaryKey(Integer id) {
		return vActivityMapper.selectByPrimaryKey(id);
	}

	@Override
	public int delActivity(Integer id) {
		return vActivityMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<Map<String, Object>> queryActivityMap(VActivity vactivity) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getActivityTotal() {
		List<VActivity> vActivityList = vActivityMapper.queryVActivity();
		return vActivityList.size();
	}

	@Override
	public int getActivityOpen() {
		List<VActivity> vActivityList = vActivityMapper.queryVActivityOpen();
		return vActivityList.size();
	}

	@Override
	public List<VActivity> queryActivityOpen() {
		
		return vActivityMapper.queryVActivityOpen();
	}

	@Override
	public VActivity selectByPrimaryKeyN(Integer id) {
		// TODO Auto-generated method stub
		return vActivityMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<VActivity> queryActivity() {
		
		return vActivityMapper.queryVActivity();
	}

}
